package com.luoran.bartalks.api;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.luoran.bartalks.core.AppUser;
import com.luoran.bartalks.entity.biz.BtContainer;
import com.luoran.bartalks.entity.biz.BtPackingListMateriel;
import com.luoran.bartalks.entity.biz.BtPlanBiz;
import com.luoran.bartalks.entity.biz.BtPlanBizPic;
import com.luoran.bartalks.entity.biz.BtPlanDetails;
import com.luoran.bartalks.entity.biz.BtPlanEntry;
import com.luoran.bartalks.entity.biz.BtPosition;
import com.luoran.bartalks.entity.biz.BtProject;
import com.luoran.bartalks.entity.biz.BtRuleRecord;
import com.luoran.bartalks.entity.biz.BtRuleRecordPic;
import com.luoran.bartalks.service.IBtContainerService;
import com.luoran.bartalks.service.IBtPackingListMaterielService;
import com.luoran.bartalks.service.IBtPackingListService;
import com.luoran.bartalks.service.IBtPlanBizService;
import com.luoran.bartalks.service.IBtPlanDetailsService;
import com.luoran.bartalks.service.IBtPlanEntryService;
import com.luoran.bartalks.service.IBtPositionService;
import com.luoran.bartalks.service.IBtProjectMemberService;
import com.luoran.bartalks.service.IOfflineDataService;
import com.luoran.bartalks.utils.DateFormatUtils;
import com.luoran.bartalks.utils.UUID;

@RestController
@RequestMapping("/api/offlineData")
public class OfflineDataApi {

	private static final Logger log = LoggerFactory.getLogger(OfflineDataApi.class);

	@Autowired
	private IBtPositionService positionService;

	@Autowired
	private IBtPackingListService packingListService;

	@Autowired
	private IBtProjectMemberService projectMemberService;

	@Autowired
	private IBtPlanDetailsService planDetailsService;

	@Autowired
	private IBtPlanEntryService planEntryService;

	@Autowired
	private IBtPackingListMaterielService packingListMaterielService;

	@Autowired
	private IBtContainerService containerService;

	@Autowired
	private IBtPlanBizService planBizService;

	@Autowired
	private IOfflineDataService service;

	@RequestMapping("/getAppProjectInfo")
	public JSONObject getAppProjectInfo() {
		log.info("获取用户项目信息");
		JSONObject res = new JSONObject();
		JSONObject data = new JSONObject();
		String companyId = AppUser.get().getCompanyId();
		List<BtProject> projectList = projectMemberService.getProjectOfAPP(AppUser.get().getId(), companyId);
		if (projectList == null || projectList.size() == 0) {
			res.put("state", false);
			res.put("msg", "该用户无有效的项目信息,请核对后再试!");
		} else {
			List<String> projectIdList = projectList.stream().map(BtProject::getId).collect(Collectors.toList());
			List<BtPlanDetails> planList = planDetailsService.getPlanByProjectIdOfAPP(projectIdList, companyId);
			List<String> planIdList = planList.stream().map(BtPlanDetails::getId).collect(Collectors.toList());
			List<BtPlanEntry> planEntry = planEntryService.getByPlanIdOfAPP(planIdList, companyId);
			/*
			 * 过滤掉没有地点的计划 计划被删除 过滤掉没有计划的项目 项目被删除
			 */
			Iterator<BtPlanDetails> planiter = planList.iterator();
			while (planiter.hasNext()) {
				BtPlanDetails plan = planiter.next();
				String id = plan.getId();
				// 过滤出符合条件的数据
				List<BtPlanEntry> filterList = planEntry.stream().filter(pe -> pe.getPlanId().equals(id))
						.collect(Collectors.toList());
				if (filterList.size() == 0) {
					planiter.remove();
				}
			}
			Iterator<BtProject> projectiter = projectList.iterator();
			while (projectiter.hasNext()) {
				BtProject project = projectiter.next();
				String id = project.getId();
				// 过滤出符合条件的数据
				List<BtPlanDetails> filterList = planList.stream().filter(pl -> pl.getProjectId().equals(id))
						.collect(Collectors.toList());
				if (filterList.size() == 0) {
					projectiter.remove();
				}
			}
			if (projectList == null || projectList.size() == 0) {
				res.put("state", false);
				res.put("msg", "该用户无有效的项目信息,请核对后再试!");
				return res;
			}
			data.put("project", projectList);
			data.put("plan", planList);
			data.put("position", planEntry);
			res.put("state", true);
			res.put("data", data);
		}
		return res;
	}

	@RequestMapping("/getAppUserInfo")
	public JSONObject getAppUserInfo() {
		log.info("获取用信息");
		JSONObject res = new JSONObject();
		res.put("name", AppUser.get().getAlias());
		res.put("company", AppUser.get().getCompanyName());
		return res;
	}

	@RequestMapping("/refreshCache")
	public JSONObject refreshCache() {
		log.info("缓存用户信息");
		JSONObject res = new JSONObject();
		String companyId = AppUser.get().getCompanyId();
		String useId = AppUser.get().getId();
		List<BtContainer> containers = containerService.getContainerBycompanyId(companyId);
		List<BtPackingListMateriel> checkMateriels = packingListMaterielService
				.checkMaterielOfAppByCompanyId(companyId);
		if (containers.size() == 0 && checkMateriels.size() == 0) {
			res.put("state", false);
			res.put("msg", "该用户公司暂无有效缓存数据,请核对后再试!");
		} else {
			// 查询所有合理可能出现的箱单
			List<BtPackingListMateriel> materiels = packingListMaterielService.getMaterielOfApp(companyId, useId);
			res.put("state", true);
			res.put("companyId", companyId);
			res.put("containers", containers);
			res.put("materiels", materiels);
		}
		return res;
	}

	@RequestMapping("/dataUpload")
	public JSONObject dataUpload(HttpServletRequest request) {
		String data = request.getParameter("data");
		log.info("数据上传");
		JSONObject res = new JSONObject();
		res.put("state", true);
		JSONObject jsonObject = JSON.parseObject(data);
		JSONArray loadOrUnloadList = jsonObject.getJSONArray("loadOrUnloadList");
		JSONArray ruleRecordList = jsonObject.getJSONArray("ruleRecordList");
		JSONArray exceptionInfoList = jsonObject.getJSONArray("exceptionInfoList");
		JSONObject otherInfo = jsonObject.getJSONObject("otherInfo");
		JSONObject project = otherInfo.getJSONObject("project");
		JSONObject plan = otherInfo.getJSONObject("plan");
		JSONObject position = otherInfo.getJSONObject("position");
		if (otherInfo.isEmpty()) {
			res.put("state", false);
			res.put("msg", "项目信息参数无效！请先选择项目信息！");
			return res;
		}

		if (!loadOrUnloadList.isEmpty()) {
			List<BtPlanBiz> planbizload = new ArrayList<BtPlanBiz>();
			List<BtPlanBiz> planbizunload = new ArrayList<BtPlanBiz>();
			List<BtPlanBizPic> planbizPics = new ArrayList<BtPlanBizPic>();
			// 判断是否是起点与终点 起点终点为装货并且没有卸货 途径点装货自动卸货
			BtPlanEntry planEntry = planEntryService.getPlanEntryById(position.getString("id"));
			if (planEntry.getSign() == 1) {
				for (Iterator<Object> iterator = loadOrUnloadList.iterator(); iterator.hasNext();) {
					boolean tag = true;
					BtPlanBiz planBiz = new BtPlanBiz();
					planBiz.setBizUser(AppUser.get().getId());
					JSONObject job = (JSONObject) iterator.next();
					if ("未知".equals(job.getString("containerName")) && "未知".equals(job.getString("containerCode"))) {
						// 容器为未知 尝试通过二维码查询 智能选择或用户选择
						BtContainer container = containerService.getContainerByQrcodeAndCompanyId(
								job.getString("containerQrcode"), AppUser.get().getCompanyId());
						if (container == null) {
							tag = false;
						} else {
							JSONObject exceptionInfo = new JSONObject();
							exceptionInfo.put("text", "离线操作存在未知数据，系统判定容器为： " + container.getContainerName() + "  "
									+ container.getContainerCode());
							exceptionInfo.put("date", DateFormatUtils.DateTime2Str(new Date()));
							exceptionInfoList.add(exceptionInfo);
							planBiz.setContainerId(container.getId());
							planBiz.setContainerName(container.getContainerName());
							planBiz.setContainerCode(container.getContainerCode());
						}
					} else {
						planBiz.setContainerId(job.getString("containerId"));
						planBiz.setContainerName(job.getString("containerName"));
						planBiz.setContainerCode(job.getString("containerCode"));
					}
					if ("未知".equals(job.get("materielName").toString()) && "未知".equals(job.getString("materielCode"))) {
						// 货物为未知 ,尝试通过二维码查询 智能选择或用户选择
						BtPackingListMateriel materiel = packingListMaterielService.getByMaterielQrcodeAndCompanyId(
								job.getString("materielQrcode"), AppUser.get().getCompanyId());
						if (materiel == null) {
							tag = false;
						} else {
							JSONObject exceptionInfo = new JSONObject();
							exceptionInfo.put("text", "离线操作存在未知数据，系统判定货物为： " + materiel.getMaterielName() + "  "
									+ materiel.getMaterielCode());
							exceptionInfo.put("date", DateFormatUtils.DateTime2Str(new Date()));
							exceptionInfoList.add(exceptionInfo);
							planBiz.setMaterielId(materiel.getId());
							planBiz.setMaterielName(materiel.getMaterielName());
							planBiz.setMaterielCode(materiel.getMaterielCode());
							planBiz.setPackingListId(materiel.getPackingListId());
						}
					} else {
						planBiz.setMaterielId(job.getString("materielId"));
						planBiz.setMaterielName(job.getString("materielName"));
						planBiz.setMaterielCode(job.getString("materielCode"));
						planBiz.setPackingListId(job.getString("pklmaterielId"));
					}
					planBiz.setProjectId(project.getString("id"));
					planBiz.setPlanId(plan.getString("id"));
					planBiz.setPlanPositionId(position.getString("id"));
					planBiz.setPlanPkgMaterielId(job.getString("pklmaterielId"));
					planBiz.setBizUser(AppUser.get().getId());
					planBiz.setBizDate(DateFormatUtils.Str2DateTimefinalNow(job.getString("date")));
					String loadID = UUID.get();
					// 拼装图片记录
					String imgType = job.getString("imgType");
					String imgs = job.getString("imgs");
					String[] imgTypeSplit = imgType.split("!");
					String[] imgsSplit = imgs.split("!");
					if (imgTypeSplit.length != imgsSplit.length) {
						tag = false;
					}
					if (tag) {
						// 根据箱单物料id,查询当前点该物料是否存在装货记录,
						BtPlanBiz persistentPlanBiz = planBizService.getItemByPackingListMaterielIdAndPlanPositionId(
								planBiz.getPackingListId(), position.getString("id"), 10);
						// 如果不存在,添加记录, 如果存在 跳过.避免重复扫描重复添加
						if (persistentPlanBiz == null) {
							// 自动异常上报
							// 判断是否是计划中的货物
							int check = packingListService.checkByPackingListIdAndPlanId(planBiz.getPackingListId(),
									plan.getString("id"), AppUser.get().getCompanyId());
							if (check == 0) {
								// 非该计划货物但是同公司下的可以捎带
								JSONObject exceptionInfo = new JSONObject();
								exceptionInfo.put("text",
										"\n编码为:" + planBiz.getMaterielCode() + " 的" + planBiz.getMaterielName()
												+ "不是计划中的货物,但是在"
												+ planEntryService.getPlanEntryById(position.getString("id"))
														.getAddressName()
												+ "装载至编码为:" + planBiz.getContainerCode() + "的"
												+ planBiz.getContainerName() + "中");
								exceptionInfo.put("date", DateFormatUtils.DateTime2Str(new Date()));
								exceptionInfoList.add(exceptionInfo);
							}
							planBiz.setId(loadID);
							planBiz.setBizType(10);
							planbizload.add(planBiz);
							for (int i = 0; i < imgsSplit.length; i++) {
								BtPlanBizPic planBizPic = new BtPlanBizPic();
								planBizPic.setId(UUID.get());
								planBizPic.setPlanBizId(loadID);
								planBizPic.setBASE64("".equals(imgsSplit[i])?"":imgsSplit[i].replaceAll(" ", "+").substring(23));
								planbizPics.add(planBizPic);
							}
						}
					}
				}
				try {
					service.loadOrUnloadInsertsBatch(planbizload, null, planbizPics, project.getString("id"),
							plan.getString("id"), position.getString("id"));
				} catch (Exception e) {
					res.put("state", false);
					res.put("msg", "系统错误，请联系管理员");
				}
			} else {
				// 获得上一个点的planPositionId
				boolean bizTag = true;
				String planPositionIdPrevious = planEntryService
						.getPlanEntryByPlanIdAndSign(planEntry.getPlanId(), AppUser.get().getCompanyId(),
								planEntry.getSign() - 1)
						.getId();
				for (Iterator<Object> iterator = loadOrUnloadList.iterator(); iterator.hasNext();) {
					boolean tag = true;
					BtPlanBiz planBiz = new BtPlanBiz();
					planBiz.setBizUser(AppUser.get().getId());
					JSONObject job = (JSONObject) iterator.next();
					if ("未知".equals(job.getString("containerName")) && "未知".equals(job.getString("containerCode"))) {
						// 容器为未知 尝试通过二维码查询 智能选择或用户选择
						BtContainer container = containerService.getContainerByQrcodeAndCompanyId(
								job.getString("containerQrcode"), AppUser.get().getCompanyId());
						if (container == null) {
							tag = false;
						} else {
							JSONObject exceptionInfo = new JSONObject();
							exceptionInfo.put("text", "离线操作存在未知数据，系统判定容器为： " + container.getContainerName() + "  "
									+ container.getContainerCode());
							exceptionInfo.put("date", DateFormatUtils.DateTime2Str(new Date()));
							exceptionInfoList.add(exceptionInfo);
							planBiz.setContainerId(container.getId());
							planBiz.setContainerName(container.getContainerName());
							planBiz.setContainerCode(container.getContainerCode());
						}
					} else {
						planBiz.setContainerId(job.getString("containerId"));
						planBiz.setContainerName(job.getString("containerName"));
						planBiz.setContainerCode(job.getString("containerCode"));
					}

					if ("未知".equals(job.get("materielName").toString()) && "未知".equals(job.getString("materielCode"))) {
						// 货物为未知 ,尝试通过二维码查询 智能选择或用户选择
						BtPackingListMateriel materiel = packingListMaterielService.getByMaterielQrcodeAndCompanyId(
								job.getString("materielQrcode"), AppUser.get().getCompanyId());
						if (materiel == null) {
							tag = false;
						} else {
							JSONObject exceptionInfo = new JSONObject();
							exceptionInfo.put("text", "离线操作存在未知数据，系统判定货物为： " + materiel.getMaterielName() + "  "
									+ materiel.getMaterielCode());
							exceptionInfo.put("date", DateFormatUtils.DateTime2Str(new Date()));
							exceptionInfoList.add(exceptionInfo);
							planBiz.setMaterielId(materiel.getId());
							planBiz.setMaterielName(materiel.getMaterielName());
							planBiz.setMaterielCode(materiel.getMaterielCode());
							planBiz.setPackingListId(materiel.getPackingListId());
						}
					} else {
						planBiz.setMaterielId(job.getString("materielId"));
						planBiz.setMaterielName(job.getString("materielName"));
						planBiz.setMaterielCode(job.getString("materielCode"));
						planBiz.setPackingListId(job.getString("pklmaterielId"));
					}
					planBiz.setProjectId(project.getString("id"));
					planBiz.setPlanId(plan.getString("id"));
					planBiz.setPlanPositionId(position.getString("id"));
					planBiz.setPlanPkgMaterielId(job.getString("pklmaterielId"));
					planBiz.setBizUser(AppUser.get().getId());
					planBiz.setBizDate(DateFormatUtils.Str2DateTimefinalNow(job.getString("date")));
					String loadID = UUID.get();
					String unloadID = UUID.get();

					// 拼装图片记录
					String imgType = job.getString("imgType");
					String imgs = job.getString("imgs");
					String[] imgTypeSplit = imgType.split("!");
					String[] imgsSplit = imgs.split("!");
					if (imgTypeSplit.length != imgsSplit.length) {
						tag = false;
					}
					if (tag) {
						// 根据箱单物料id,查询当前点该物料是否存在装货记录,
						BtPlanBiz persistentPlanBiz = planBizService.getItemByPackingListMaterielIdAndPlanPositionId(
								planBiz.getPackingListId(), position.getString("id"), 10);
						// 如果不存在,添加记录, 如果存在 跳过.避免重复扫描重复添加
						if (persistentPlanBiz == null) {
							// 查询是否是该计划上一点的物料
							BtPlanBiz planBizPrevious = planBizService.findmaterielByPlanpositionIdAndplanId(
									plan.getString("id"), planBiz.getMaterielId(), planPositionIdPrevious);
							// 非上一地点已装则视为异常信息处理 并自动上报
							if (planBizPrevious == null) {
								// 自动异常上报
								// 判断是否是计划中的货物
								int check = packingListService.checkByPackingListIdAndPlanId(planBiz.getPackingListId(),
										plan.getString("id"), AppUser.get().getCompanyId());
								if (check == 0) {
									// 非该计划货物但是同公司下的可以捎带
									JSONObject exceptionInfo = new JSONObject();
									exceptionInfo.put("text",
											"\n编码为:" + planBiz.getMaterielCode() + " 的" + planBiz.getMaterielName()
													+ "不是计划中的货物,但是在"
													+ planEntryService.getPlanEntryById(position.getString("id"))
															.getAddressName()
													+ "装载至编码为:" + planBiz.getContainerCode() + "的"
													+ planBiz.getContainerName() + "中");
									exceptionInfo.put("date", DateFormatUtils.DateTime2Str(new Date()));
									exceptionInfoList.add(exceptionInfo);
								} else {
									// 是该计划的货物但不是从上一点装来的
									JSONObject exceptionInfo = new JSONObject();
									exceptionInfo.put("text", "\n编码为:" + planBiz.getMaterielCode() + " 的"
											+ planBiz.getMaterielName() + "装卸货地点异常");
									exceptionInfo.put("date", DateFormatUtils.DateTime2Str(new Date()));
									exceptionInfoList.add(exceptionInfo);
								}
							} else {
								// 是上一地点的物料 从上一个地点装的容器中卸载
								planBiz.setId(unloadID);
								planBiz.setBizType(20);
								planbizunload.add(planBiz);
								for (int i = 0; i < imgsSplit.length; i++) {
									BtPlanBizPic planBizPic = new BtPlanBizPic();
									planBizPic.setId(UUID.get());
									planBizPic.setPlanBizId("20".equals(imgTypeSplit[i]) ? unloadID :loadID );
									planBizPic.setBASE64(imgsSplit[i].replaceAll(" ", "+").substring(23));
									planbizPics.add(planBizPic);
								}
								bizTag = false;
							}
							// 无论是不是上一点装货 都可以在此地点装卸货
							planBiz.setId(loadID);
							planBiz.setBizType(10);
							planbizload.add(planBiz);
							if (bizTag) {
								// 只添加为10的
								for (int i = 0; i < imgsSplit.length; i++) {
									if ("10".equals(imgTypeSplit[i])) {
										BtPlanBizPic planBizPic = new BtPlanBizPic();
										planBizPic.setId(UUID.get());
										planBizPic.setPlanBizId(loadID);
										planBizPic.setBASE64("".equals(imgsSplit[i])?"":imgsSplit[i].replaceAll(" ", "+").substring(23));
										planbizPics.add(planBizPic);
									}
								}
							}
						}

					}
				}
				try {
					service.loadOrUnloadInsertsBatch(planbizload, planbizunload, planbizPics, project.getString("id"),
							plan.getString("id"), position.getString("id"));
				} catch (Exception e) {
					e.printStackTrace();
					res.put("state", false);
					res.put("msg", "系统错误，请联系管理员");
				}
			}
		}

		if (!ruleRecordList.isEmpty()) {
			List<BtRuleRecord> ruleRecords = new ArrayList<BtRuleRecord>();
			List<BtRuleRecordPic> ruleRecordPics = new ArrayList<BtRuleRecordPic>();
			for (Iterator<Object> iterator = ruleRecordList.iterator(); iterator.hasNext();) {
				boolean tag = true;
				BtRuleRecord ruleRecord = new BtRuleRecord();
				JSONObject job = (JSONObject) iterator.next();
				String ruleRecordId = UUID.get();
				ruleRecord.setId(ruleRecordId);
				BtPosition positionById = positionService.getPositionById(planEntryService.getPlanEntryById(position.getString("id")).getAddressId());
				ruleRecord.setPositionId(positionById.getId());
				ruleRecord.setPositionName(positionById.getPositionName());
				ruleRecord.setLatitude(new BigDecimal(positionById.getLatitude()));
				ruleRecord.setLongitude(new BigDecimal(positionById.getLongitude()));
				ruleRecord.setLength(new BigDecimal(job.getString("length")));
				ruleRecord.setWidth(new BigDecimal(job.getString("width")));
				ruleRecord.setHeight(new BigDecimal(job.getString("height")));
				ruleRecord.setWeight(new BigDecimal(job.getString("weight")));
				ruleRecord.setDescription(job.getString("description"));
				ruleRecord.setRuleDate(DateFormatUtils.Str2DateTimefinalNow(job.getString("date")));
				ruleRecord.setCompanyId(AppUser.get().getCompanyId());
				ruleRecord.setOperator(AppUser.get().getAlias());
				ruleRecord.setOperatorId(AppUser.get().getId());
				if ("未知".equals(job.get("materielName").toString()) && "未知".equals(job.getString("materielCode"))) {
					ruleRecord.setIsException("1");
					BtPackingListMateriel packingListMateriel = packingListMaterielService
							.getByMaterielQrcodeAndCompanyId(job.getString("materielQrcode"),
									AppUser.get().getCompanyId());
					if (packingListMateriel == null) {
						/*
						 * res.put("state", false); res.put("msg",
						 * "未查询到二维码为："+job.getString("qrcode")+"的货物，请核对后再试!"); return res;
						 */
						tag = false;
					} else {
						JSONObject exceptionInfo = new JSONObject();
						exceptionInfo.put("text", "离线操作存在未知数据，系统判定货物为： " + packingListMateriel.getMaterielName() + "  "
								+ packingListMateriel.getMaterielCode());
						exceptionInfo.put("date", DateFormatUtils.DateTime2Str(new Date()));
						exceptionInfoList.add(exceptionInfo);
						ruleRecord.setResourceId(packingListMateriel.getMaterielId());
						ruleRecord.setResourceCode(packingListMateriel.getMaterielCode());
						ruleRecord.setResourceName(packingListMateriel.getMaterielName());
						ruleRecord.setPackingListMaterielId(packingListMateriel.getId());
					}
				} else {
					ruleRecord.setResourceId(job.getString("materielId"));
					ruleRecord.setResourceCode(job.getString("materielCode"));
					ruleRecord.setResourceName(job.getString("materielName"));
					ruleRecord.setPackingListMaterielId(job.getString("pklmaterielId"));
					ruleRecord.setIsException("0");
				}
				if (tag) {
					ruleRecords.add(ruleRecord);
					String imgs = job.getString("imgs");
					String[] imgsSplit = imgs.split("!");
					for (int i = 0; i < imgsSplit.length; i++) {
						BtRuleRecordPic ruleRecordPic = new BtRuleRecordPic();
						ruleRecordPic.setId(UUID.get());
						ruleRecordPic.setBASE64("".equals(imgsSplit[i])?"":imgsSplit[i].replaceAll(" ", "+").substring(23));
						ruleRecordPic.setRuleRecordId(ruleRecordId);
						ruleRecordPics.add(ruleRecordPic);
					}
				}
			}
			try {
				service.ruleRecordListInsertsBatch(ruleRecords, ruleRecordPics);
			} catch (Exception e) {
				e.printStackTrace();
				res.put("state", false);
				res.put("msg", "系统错误，请联系管理员");
			}
		}

		if (!exceptionInfoList.isEmpty()) {
			BtPlanEntry btPlanEntry = planEntryService.getPlanEntryById(position.getString("id"));
			if (btPlanEntry == null) {
				res.put("state", false);
				res.put("msg", "地点信息有误，请核对后再试！");
			} else {
				String exception = btPlanEntry.getException();
				if (exception == null) {
					exception = "";
				}
				for (Iterator<Object> iterator = loadOrUnloadList.iterator(); iterator.hasNext();) {
					JSONObject job = (JSONObject) iterator.next();
					exception = exception + "\n:" + job.getString("text");
				}
				planEntryService.updateExceptionInfo(btPlanEntry.getId(), btPlanEntry.getPlanId(), exception);
			}
		}
		return res;
	}

}
